package org.example.SlApi.RyxxApi;

import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.example.JycInfo;
import org.example.utils.ReadConf;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import static org.example.CookieHandlingFilter.cookies;
import static org.example.RestClient.givenWithCookies;
import static org.example.RestClient.loginAndUpdateCookies;
import static org.example.SlApi.JbxxApi.JbxxbcApi.initJyclist;

public class Tzr2API {//人员信息-股东一号信息保存
    public static void main(String[] args) throws IOException {    //企业开办
        tzr2API();
    }
    private static List<JycInfo> JycList = new ArrayList<>();

    public static int tzr2API() throws IOException {
        // 登录并更新cookies

        loginAndUpdateCookies();

        RestAssured.baseURI = ReadConf.getHost(); // 设置基础URI
        List<JycInfo> jycInfoList = initJyclist(); // 调用方法来获取列表
        if (!jycInfoList.isEmpty()) {
            JycInfo firstJycInfo = jycInfoList.get(0); // 获取列表中的第一个元素
            String pripid = firstJycInfo.getPripid(); // 使用实际的getter方法
            String sbid = firstJycInfo.getSbid();


            String data = "ywtSldj.do?method=saveGd&qytzfxx=S_CERTYPE_%3A11_%2CS_INV_%3A%E4%B9%89%E4%B9%8C%E7%AD%89%E5%93%88%E6%97%B6%E9%97%B4%E4%BE%BF%E5%88%A9%E6%A0%88%EF%BC%88%E4%B8%AA%E4%BD%93%E5%B7%A5%E5%95%86%E6%88%B7%EF%BC%89_%2CS_CERNO_%3A92330782MA28QHGP2F_%2CS_DOM_%3A%E5%A4%A7%E5%B8%88%E5%82%85%E5%9C%B0%E6%96%B9_%2CS_FDDBR_%3A%E6%A0%97%E4%BC%9A_%2CS_MOBTEL_%3A13568547854_%2CS_FDDBRCERNO_%3A142726197009280616_%2CS_PRIPID_%3A"+pripid+"_%2CS_INVID_%3A_%2CD_CONDATE_%3A2024-09-14_%2CS_INVTYPE_%3A1_%2CS_SUBCONAM_%3A400_%2CS_CONFORM_%3A1%2C_%2CS_FDDBRCERTYPE_%3A10_%2CS_SUBCONPROP_%3A40_%2CS_COUNTRY_%3A156&gdczmxList=1~_400~_2024-09-14~_~~_&pripid="+pripid+"&sbid="+sbid+"&yyzzpath=&zmpath=&fmpath=&hkbpath=&hzpath=&baseZheng=&baseFan=&baseHKB=&baseHZ=&baseYYZZ=&sfzdrtype=0&csrftoken=";
            Response response = givenWithCookies()

                    .header("Content-Type","multipart/form-data; boundary=----WebKitFormBoundary6FLIcZL51kmdTR9Y")
//               .cookies(cookies)

                    .log().all()
                    .post(data);
            System.out.println(cookies);
            int statusCode = Integer.parseInt(String.valueOf(response.getStatusCode()));
            System.out.println(statusCode);
            String body = response.getBody().asString();
            System.out.println(body);
            if (statusCode == 302) {

                String redirectUrl = response.getHeader("Location");
                System.out.println(redirectUrl);
                if (redirectUrl != null) {
                    Response finalResponse = givenWithCookies()
                            .log().all()
                            .when()
                            .get(redirectUrl);
                    int statusCode1 = finalResponse.getStatusCode();
                    System.out.println("Status Code: " + statusCode);



//        Response response2 = givenWithCookies() //查看人员保存信息
//
//
//
//                .get("ywtSldj.do?method=eidtGd&pripid=${pripid}&sbid=${sbid}&invid=2&reslut=saveSussess&sfzdrtype=0&csrftoken=${csrftoken}"); // 注意：可能需要有效的 CSRF Token
//        System.out.println(cookies);
//        int statusCode1 = Integer.parseInt(String.valueOf(response2.getStatusCode()));
//        System.out.println(statusCode1);
//        String body1 = response2.getBody().asString();
//        System.out.println(body1);
//
//        Map<String, String> formParams1 = new HashMap<>();
//        formParams1.put("method", "edit");
//        formParams1.put("sbid", "${sbid}");
//        formParams1.put("pripid", "${pripid}");
//        formParams1.put("entname", "${entname}");
//        formParams1.put("entid", "${entid}");
//        formParams1.put("enttype", "1130");
//        formParams1.put("regno", "");
//        formParams1.put("regorg", "330102");
//        formParams1.put("qylxdl", "11");
//        formParams1.put("sbms", "1");
//        formParams1.put("ljmsign", "2");
//        formParams1.put("znspsign", "0");
//        formParams1.put("bdcsign", "");
//        formParams1.put("name_id", "${name_id}");
//        formParams1.put("S_ITE", "0");
//        formParams1.put("S_ITENAME", "");
//        formParams1.put("S_ITEREGNO", "");
//        formParams1.put("currentTab_ryxx", "");
//        formParams1.put("llry", "");
//        formParams1.put("cwry", "");
//        formParams1.put("XB_LL", "2");
//        formParams1.put("zmpath_ll", "/330000/330100/330102/2024/2024072700005631/20240727141649000704.jpg");
//        formParams1.put("fmpath_ll", "/330000/330100/330102/2024/2024072700005631/20240727141652000050.jpg");
//        formParams1.put("hkbpath_ll", "/330000/330100/330102/2024/2024072700005631/20240727141649000704.jpg");
//        formParams1.put("hzpath_ll", "/330000/330100/330102/2024/2024072700005631/20240727141649000704.jpg");
//        formParams1.put("NAME_OCR_ll", "");
//        formParams1.put("CERNO_OCR_ll", "");
//        formParams1.put("ADDRESS_OCR_ll", "");
//        formParams1.put("VALID_UNTIL_OCR_ll", "");
//        formParams1.put("ISGXTQ_ll", "");
//        formParams1.put("GXTQTIME_ll", "");
//        formParams1.put("baseZheng_ll", "/330000/330100/330102/2024/2024072700005631/20240727141649000704.jpg");
//        formParams1.put("baseFan_ll", "/330000/330100/330102/2024/2024072700005631/20240727141652000050.jpg");
//        formParams1.put("baseHZ_ll", "/330000/330100/330102/2024/2024072700005631/20240727141649000704.jpg");
//        formParams1.put("baseHKB_ll", "/330000/330100/330102/2024/2024072700005631/20240727141649000704.jpg");
//        formParams1.put("csrftoken", "");
//
//
//
//        Response wjzs = givenWithCookies() //上传文件保存
//
//                .params(formParams1)
//
//                .get("ywtSldj.do?method=edit&select_mkid=2"); // 注意：可能需要有效的 CSRF Token
//        System.out.println(cookies);
//        int statusCode2 = Integer.parseInt(String.valueOf(wjzs.getStatusCode()));
//        System.out.println(statusCode2);
//        String body2 = wjzs.getBody().asString();
//        System.out.println(body2);



        return statusCode;
    }

}
        }
        return 0;
    }
}
